package com.ling.sbbyyds.mapper.user;

import com.ling.sbbyyds.entity.users.UserAtt;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.ArrayList;

public interface UserAttMapper extends Mapper<UserAtt> {

    /**
     * 获取用户关注列表
     * @param userId  用户id
     * @return
     */
    @Select("select bei_user_id as beiUserId from sbb_user_att where user_id = #{userId} and state = 1 order by time desc limit #{limitStart},#{limit}")
    ArrayList<UserAtt> getAttUserList(@Param("userId")Long userId,@Param("limitStart")Integer limitStart,@Param("limit")Integer limit);

    /**
     * 获取好友列表
     * @param userId  用户id
     * @return
     */
    @Select("SELECT\n" +
            "a.user_id AS userId\n" +
            "FROM\n" +
            "sbb_user_att a\n" +
            "WHERE\n" +
            "a.user_id in (\n" +
            "SELECT\n" +
            "a.bei_user_id AS beiUserId\n" +
            "FROM sbb_user_att a\n" +
            "WHERE\n" +
            "a.user_id = #{userId}\n" +
            "AND a.state = 1\n" +
            ")\n" +
            "AND a.state = 1 and bei_user_id = #{userId}\n" +
            "ORDER BY\n" +
            "a.time DESC limit #{limitStart},#{limit}")
    ArrayList<UserAtt> getFriendsList(@Param("userId")Long userId,@Param("limitStart")Integer limitStart,@Param("limit")Integer limit);

    /**
     * 获取用户关注数
     * @param userId  用户id
     * @return
     */
    @Select("select count(1) from sbb_user_att where user_id = #{userId} and state = 1")
    Integer getAttUserListCount(@Param("userId")Long userId);



    /**
     * 获取  朋友列表
     * @param userId  用户id
     * @return
     */
    @Select("select bei_user_id as beiUserId from sbb_user_att where user_id = #{userId} and state = 1 order by time desc limit #{limitStart},#{limit}")
    ArrayList<UserAtt> getFriendLists(@Param("userId")Long userId, @Param("beiserId")Long beiUserId,
                                      @Param("limitStart")Integer limitStart, @Param("limit")Integer limit);


    /**
     * 获取  朋友列表
     * @param userId  用户id
     * @return
     */
    @Select("select bei_user_id as beiUserId from sbb_user_att where user_id = #{userId} and state = 1 order by time desc limit #{limitStart},#{limit}")
    Integer getFriendLists(@Param("userId")Long userId, @Param("beiserId")Long beiUserId);

}
